import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @Author: wenjingyuan
 * @Date: 2022/03/12/13:39
 * @Description:
 */
public class DeleteCity {
    public static void main(String[] args) throws SQLException {
        //1.得到数据源
        MysqlDataSource dataSource=new MysqlDataSource();
        //设置URL
        dataSource.setURL("jdbc:mysql://127.0.0.1:3306/java33?characterEncoding=utf8&useSSL=true");
        dataSource.setUser("root");
        dataSource.setPassword("12345678");
        //2.得到连接
        Connection connection= (Connection) dataSource.getConnection();

        //3.先组装SQL，再得到执行器
        String deleteSql="delete from city where id=?";
        PreparedStatement statement=connection.prepareStatement(deleteSql);
        statement.setInt(1,4);
        //4.执行SQL
        int result=statement.executeUpdate();
        System.out.println("受影响的行:"+result);
        //5.关闭资源
        statement.close();
        connection.close();
    }
}